package page.sample;

import java.util.List;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.DataView;
import org.apache.wicket.markup.repeater.data.ListDataProvider;

import dao.impl.FlightDao;
import entity.Flight;
import entity.User;
import page.MyFirstWebPage;

public class FlightPage extends WebPage {

	public FlightPage(final User user) {

		final FlightDao flightDao = new FlightDao(
				app.MyFirstWebApplication.DATA_XML_FOLDER);
		

		add(new Link("ShowFlight") {

			@Override
			public void onClick() {
				setResponsePage(new FlightPage(user));
			}

		});

		add(new Link("ShowTicket") {

			@Override
			public void onClick() {
				setResponsePage(new ShowTicketPage(user));

			}

		});

		add(new Link("exit") {

			@Override
			public void onClick() {
				setResponsePage(new MyFirstWebPage());

			}

		});
		
		add(new DataView<Flight>("table-rows",
				new ListDataProvider<Flight>(flightDao.getAll())) {
			@Override
			protected void populateItem(final Item<Flight> item) {
				final Flight flight = item.getModelObject();
				// add data for table cell in row
				item.add(new Label("name", flight.getName()));
				item.add(new Label("date", flight.getDate()));
				item.add(new Label("time", flight.getTime()));
				item.add(new Label("price", flight.getPrice()));
				item.add(new Label("emptySeats", flight.getEmptySeats()));

				// add button component to open "edit" page
				item.add(new Link("reservation") {
					@Override
					public void onClick() {
						setResponsePage(new TicketPage(user, flight));
					}
				});
			}
		});
	}

}
